#include <iostream>

using namespace std;

//本质上题目问的是：有没有一个整数 mid，满足 mid * mid == num
class Solution 
{
public:
	bool isPerfectSquare(int num) 
	{
		if (num == 1) 
		{
			return true;
		}
		
		int left = 1;
		int right = num / 2;		//除 1 以外，任何数的平方根都不会超过它本身的一半。
									//减少无效搜索区间，提高效率.
		
		while (left <= right) 
		{
			int mid = left + (right - left) / 2;
			
			if ((long long)mid * mid == num) 
			{
				return true;
			}
			else if ((long long)mid * mid < num) 
			{
				left = mid + 1;
			}
			else 
			{
				right = mid - 1;
			}
		}
		
		return false;
	}
};

int main() 
{
	Solution sol;
	int num;
	
	cout << "请输入正整数 num: ";
	cin >> num;
	
	if (sol.isPerfectSquare(num)) 
	{
		cout << "true" << endl;
	}
	else 
	{
		cout << "false" << endl;
	}
	
	return 0;
}

